<template>
  <BasicModal @register="register" :title="'选项成品不合格类型'" @ok="handleSubmit" width="30%">
    <BasicForm @register="registerForm" />
  </BasicModal>
</template>
<script lang="ts">
  export default defineComponent({
    name: 'WorkCalendarModal',
  });
</script>
<script setup lang="ts">
  import { defineComponent, ref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { BasicForm, FormSchema, useForm } from '/@/components/Form';

  const emit = defineEmits(['success', 'register']);
  const { showMessage } = useMessage();

  const [register, { closeModal, setModalProps }] = useModalInner(async (e) => {
    await resetFields();
    let inputFormSchemas: FormSchema[] = [];
    inputFormSchemas = [
      {
        field: 'remarksCode',
        fieldLabel: 'remarksName',
        component: 'Select',
        componentProps: {
          dictType: 'm8_bhg_cp_type',
          allowClear: true,
          mode: 'multiple',
          rows: 3,
        },
        required: true,
      },
    ];
    setProps({
      labelWidth: 10,
      schemas: inputFormSchemas,
      baseColProps: { lg: 24, md: 24 },
    });
  });

  async function handleSubmit() {
    try {
      const data = await validate();
      // const data = await validate();
      // setModalProps({ confirmLoading: true });
      // const params: any = {
      //   selIds: value.value.id,
      //   ...data
      // };
      // // console.log('submit', params, data, record);
      // const res = await testTreeSave(params, data);
      // showMessage(res.message);
      setTimeout(closeModal);
      emit('success', data);
    } catch (error: any) {
      if (error && error.errorFields) {
        showMessage('您填写的信息有误，请根据提示修正。');
      }
      console.log('error', error);
    } finally {
      setModalProps({ confirmLoading: false });
    }
  }
  const [registerForm, { resetFields, validate, setProps, updateSchema }] = useForm();
</script>
<style scoped>
  .ant-picker {
    width: 80%;
  }
</style>
